<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">

    <title>斗鱼播放</title>

    <script src="js/util.js"></script>


    <link href="https://cdn.bootcss.com/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.bootcss.com/twitter-bootstrap/4.1.3/js/bootstrap.min.js"></script>

    <script src="js/ckplayer/ckplayer/ckplayer.js" charset="utf-8"></script>


</head>

<body>

<div id="video" style="width:100%;height:600px"></div>


<script>
    function getUrlParam(name) {
        //构造一个含有目标参数的正则表达式对象
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        //匹配目标参数
        var r = window.location.search.substr(1).match(reg); //搜索
        //返回参数值
        if (r != null) return unescape(r[2]);
        return null;
    }

    function flv_load() {
        var roomid = getUrlParam('roomid');
        var data = {
            "roomid": roomid
        };
        Util.postJson("./common-server/douyu/api/v1/room", data, function (response) {
            var data = response.data;
            var playUrl = data.rtmp_url + '/' + data.rtmp_live;

            console.log(playUrl);

            var videoObject = {
                container: '#video',//“#”代表容器的ID，“.”或“”代表容器的class
                variable: 'player',//该属性必需设置，值等于下面的new chplayer()的对象
                flashplayer: false,//如果强制使用flashplayer则设置成true
                autoplay: true,
                // video: {
                //     file: playUrl,//视频地址
                //     type: 'video/flv'
                // }
                video: [//视频地址列表形式
                    [playUrl, 'video/flv', '自动', 5],
                    // [playUrl, 'video/flv', '中文标清', 4]
                ]
            };

            new ckplayer(videoObject);

        })


    }


    $(function () {
        flv_load();
    })
</script>


</body>

</html>